﻿using System;
using System.Threading.Tasks;
using SmartCity.Shared;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace MetroManagement
{
    /// <summary>
    /// 声明应用服务类
    /// </summary>
    public class StatementAppService : ApplicationService, IStatementAppService
    {
        private readonly IRepository<Statement, int> _statementRepository;

        public StatementAppService(
            IRepository<Statement, int> statementRepository)
        {
            _statementRepository = statementRepository;
        }

        // 获取
        public async Task<ResultResponse<StatementDto>> GetAsync(string type)
        {
            var enumType = (StatementType)Enum.Parse(typeof(StatementType), type);
            var statement = await _statementRepository.GetAsync(m => m.Type == enumType);
            var dto = ObjectMapper.Map<Statement, StatementDto>(statement);
            return ResultResponse<StatementDto>.Successful(dto);
        }
    }
}